#include "stdlib.h"
#include "userModularFunctionInteger.hh"
#include "fibo.hh"
using namespace std;

void fibo::userModularFunction(fixedBitSizeInteger p){

    if(n<2){
        storeResult((fixedBitSizeInteger)n, p);//return the result
    }else
    {
        unsigned long long fibo=1;
        unsigned long long fibo_p=1;
        unsigned long long tmp=0;
        unsigned long long i=0;
        for( i=0;i<n-2;i++){
            tmp = (fibo+fibo_p) % p;
            fibo_p=fibo;
            fibo=tmp;
        }
        storeResult((fixedBitSizeInteger)fibo, p);//return the result
    }


}
fibo::fibo(vector<string>& args):userModularFunctionInteger(args){

    if(args.size() < 1)
        throw "no argument for fibonnaci!";

    n = (fixedBitSizeInteger) atol(args[0].c_str());



}
